package com.connection.second.wallpaper.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.connection.second.common.annotation.Anonymous;
import com.connection.second.wallpaper.domain.dto.UserScoreDto;
import com.connection.second.wallpaper.domain.entity.PaperHomeBanner;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.connection.second.common.annotation.Log;
import com.connection.second.common.core.controller.BaseController;
import com.connection.second.common.core.domain.AjaxResult;
import com.connection.second.common.enums.BusinessType;
import com.connection.second.wallpaper.domain.entity.PaperWall;
import com.connection.second.wallpaper.service.IPaperWallService;
import com.connection.second.common.utils.poi.ExcelUtil;
import com.connection.second.common.core.page.TableDataInfo;

/**
 * wallController
 * 
 * @author fl
 * @date 2024-11-12
 */
@Api("壁纸管理")
@RestController
@RequestMapping("/wallpaper/wall")
public class PaperWallController extends BaseController
{
    @Resource
    private IPaperWallService paperWallService;

    /**
     * 随机获取首页海报管理列表
     */
    @ApiOperation("随机获取壁纸列表")
    @Anonymous
    @GetMapping("/randomWall")
    public TableDataInfo randomWall()
    {
        startPage();
        List<PaperWall> list = paperWallService.selectRandomWall();
        return getDataTable(list);
    }

    @ApiOperation("用户给壁纸评分")
    @PreAuthorize("@ss.hasAnyRoles('user,admin')")
    @Log(title = "用户给壁纸评分", businessType = BusinessType.UPDATE)
    @PutMapping("/score")
    public AjaxResult score(@RequestBody UserScoreDto dto)
    {

        return toAjax(paperWallService.updatePaperWallScore(Long.parseLong(dto.getWallId()), dto.getScore()));
    }




    /**
     * 查询wall列表
     */
    @ApiOperation("查询壁纸列表")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(PaperWall paperWall)
    {
        startPage();
        List<PaperWall> list = paperWallService.selectPaperWallList(paperWall);
        return getDataTable(list);
    }


    /**
     * 获取wall详细信息
     */
    @ApiOperation("获取壁纸详细信息")
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(paperWallService.selectPaperWallById(id));
    }

    /**
     * 新增wall
     */
    @PreAuthorize("@ss.hasPermi('wallpaper:wall:add')")
    @Log(title = "wall", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PaperWall paperWall)
    {
        return AjaxResult.success(paperWallService.insertPaperWall(paperWall));
    }

    /**
     * 修改wall
     */
//    @PreAuthorize("@ss.hasPermi('wallpaper:wall:edit')")
    @PreAuthorize("@ss.hasAnyRoles('user,admin')")
    @Log(title = "wall", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PaperWall paperWall)
    {
        return toAjax(paperWallService.updatePaperWall(paperWall));
    }

    /**
     * 删除wall
     */
    @PreAuthorize("@ss.hasPermi('wallpaper:wall:remove')")
    @Log(title = "wall", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(paperWallService.deletePaperWallByIds(ids));
    }
}
